package cn.tedu.orderservice.rabbitmq;

import cn.tedu.orderservice.config.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RabbitMQProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到正常的订单队列
     * 正常的订单队列,没有消费者
     * 消息设置了生存时间
     * 在生存时间过期后,消息会转发到死信队列
     * @param orderId
     */
    public void sendOrder(String orderId) {
        log.debug("通过rabbitmq发送消息:{}",orderId);
        rabbitTemplate.convertAndSend(
                RabbitMqConfig.ORDER_EXCHANGE,
                RabbitMqConfig.ORDER_ROUTING_KEY,
                orderId);
    }

}
